/* GUI CONVERTED from rcsqrp01.p (converter v1.76) Fri May  3 13:22:33 2002 */
/* rcsqrp01.p - SEQUENCE SCHEDULE COMPARISON REPORT                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.10 $                                                     */
/*V8:ConvertMode=FullGUIReport                                          */
/* REVISION: 9.1   CREATED       : 10/06/99     BY: *N003* Steve Nugent */
/* REVISION: 9.1   LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1   LAST MODIFIED: 08/12/00      BY: *N0KP* myb              */
/* $Revision: 1.10 $    BY: Katie Hilbert         DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i}

define variable in_rlid_one         like rcs_rlse_id no-undo.
define variable in_rlid_two         like rcs_rlse_id no-undo.
define variable wk_curr_rlid        like rcs_rlse_id no-undo.
define variable wk_prev_rlid        like rcs_rlse_id no-undo.
define variable diff_qty            like ld_qty_oh
                                    label "Qty Diff" no-undo.
define variable cum_diff_qty        like ld_qty_oh
                                    label "Cum Qty Diff" no-undo.
define variable so_from             like so_nbr no-undo.
define variable so_to               like so_nbr no-undo.
define variable var_variance        as  decimal
                                    format "99" label "Variance % " no-undo.
define variable wk_percent_qty      as decimal format "999.999" no-undo.
define variable wk_percent_cum      as decimal format "999.999" no-undo.
define variable wk_variance         as decimal format ".99" no-undo.
define variable var_abc_class       as  character
                                    format "x" label "ABC Class" no-undo.
define variable wk_del_flag         like mfc_logical no-undo.
define variable wk_delta            like rcsd_discr_qty no-undo.
define variable wk_upper_lmt        like rcsd_discr_qty no-undo.
define variable wk_lower_lmt        like rcsd_discr_qty no-undo.
define variable part_from           like sod_part no-undo.
define variable part_to             like sod_part no-undo.
define variable shipfrom_from       like scx_shipfrom no-undo.
define variable shipfrom_to         like scx_shipfrom no-undo.
define variable shipto_from         like so_ship no-undo.
define variable shipto_to           like so_ship no-undo.
define variable curr_schd_discr_qty like rcsd_discr_qty no-undo.
define variable prev_schd_discr_qty like rcsd_discr_qty no-undo.
define variable curr_active_date    like rcs_active_date no-undo.

define temp-table ship_schd_day no-undo
   field ssd_nbr       like so_nbr
   field ssd_line      like rcsd_line
   field ssd_date      like rcsd_date
   field ssd_part      like sod_part
   field ssd_desc      like pt_desc1
   field ssd_curr_rlid like rcsd_rlse_id
                       label "Current Release ID"
   field ssd_prev_rlid like rcsd_rlse_id
                       label "Previous Release ID"
   field ssd_curr_flag as logical
   field ssd_prev_flag as logical
   field ssd_curr_qty  like rcsd_discr_qty
   field ssd_prev_qty  like rcsd_discr_qty
   field ssd_curr_cum  like rcsd_cum_qty
   field ssd_prev_cum  like rcsd_cum_qty
   field ssd_cum_qty   like rcsd_cum_qty
   field ssd_pct_qty   as decimal
                       format "ZZZ99"
                       label "Variance % "
   field ssd_pct_cum   as decimal
                       format "ZZZ99"
                       label "Variance % "
   field ssd_shipfrom  like rcsd_shipfrom
   field ssd_shipto    like rcsd_shipto
   index ssd_index1    is unique primary
      ssd_nbr
      ssd_line
      ssd_date.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shipfrom_from        colon 20 label "Ship-From"
   shipfrom_to          colon 50 label {t001.i}
   shipto_from          colon 20
   shipto_to            colon 50 label {t001.i}
   part_from            colon 20
   part_to              colon 50 label {t001.i}
   so_from              colon 20 label "Order"
   so_to                colon 50 label {t001.i}
   skip (1)
   var_variance         colon 20
   var_abc_class        colon 20
   skip (1)
   in_rlid_one          colon 20 label "Current Release ID"
   in_rlid_two          colon 20 label "Previous Release ID"
   skip (1)
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{wbrp01.i}


/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

   display var_variance with frame a.
   if so_to       = hi_char then so_to       = "".
   if part_to     = hi_char then part_to     = "".
   if shipto_to   = hi_char then shipto_to   = "".
   if shipfrom_to = hi_char then shipfrom_to = "".
   if c-application-mode <> 'WEB' then
   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update
      &fields = " shipfrom_from shipfrom_to
        shipto_from shipto_to part_from part_to so_from
        so_to var_variance var_abc_class in_rlid_one in_rlid_two "
      &frm = "a"}

   if (c-application-mode <> 'WEB')  or
      (c-application-mode = 'WEB' and
      (c-web-request begins 'DATA'))
   then do:
      bcdparm = "".
      {mfquoter.i shipfrom_from }
      {mfquoter.i shipfrom_to   }
      {mfquoter.i shipto_from   }
      {mfquoter.i shipto_to     }
      {mfquoter.i part_from     }
      {mfquoter.i part_to       }
      {mfquoter.i so_from       }
      {mfquoter.i so_to         }
      {mfquoter.i var_variance  }
      {mfquoter.i var_abc_class }
      {mfquoter.i in_rlid_one   }
      {mfquoter.i in_rlid_two   }

      if so_to       = "" then so_to       = hi_char.
      if part_to     = "" then part_to     = hi_char.
      if shipto_to   = "" then shipto_to   = hi_char.
      if shipfrom_to = "" then shipfrom_to = hi_char.
   end.  /* do */

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:



   {mfphead2.i}

   /* Main Loop */
   assign wk_variance = var_variance / 100.
   for each so_mstr
      where (so_nbr >= so_from and so_nbr <= so_to) and
            (so_ship >= shipto_from and so_ship <= shipto_to)
            and so_seq_order no-lock,
      each sod_det
         where so_nbr = sod_nbr and
         (sod_part >= part_from and sod_part <= part_to) and
         (sod_site >= shipfrom_from and sod_site <= shipfrom_to)
         no-lock,
      each pt_mstr
         where pt_part = sod_part no-lock:

      if var_abc_class <> "" then
         if pt_abc <> var_abc_class then
            next.
      if (in_rlid_one = "" or in_rlid_two = "" )
      then do:

         for last rcs_mstr where
            rcs_shipto = so_ship and
            rcs_shipfrom = sod_site and
            rcs_active
            use-index rcs_index3
         no-lock:
         end.
         if not available rcs_mstr then
            next.
         else
            assign
               curr_active_date = rcs_active_date
               wk_curr_rlid = rcs_rlse_id.

         find prev rcs_mstr where
            rcs_shipto = so_ship and
            rcs_shipfrom = sod_site and
            not rcs_active and
            rcs_active_date <= curr_active_date
            use-index rcs_index3
         no-lock no-error.

         if not available rcs_mstr then
            next.
         else
            wk_prev_rlid = rcs_rlse_id.

      end. /* if then do */

      else do:
         for last rcs_mstr where rcs_rlse_id = in_rlid_one and
            rcs_shipto = so_ship and
            rcs_shipfrom = sod_site and
            rcs_active
            use-index rcs_index3
         no-lock:
         end.
         if not available rcs_mstr then
            next.
         else
            assign
               wk_curr_rlid = rcs_rlse_id
               curr_active_date = rcs_active_date.

         for last rcs_mstr where rcs_rlse_id = in_rlid_two and
            rcs_shipto = so_ship and
            rcs_shipfrom = sod_site and
            not rcs_active and
            rcs_active_date <= curr_active_date
            use-index rcs_index3
         no-lock:
         end.
         if not available rcs_mstr then
            next.
         else
            wk_prev_rlid = rcs_rlse_id.

      end. /* else do */

      for last rcs_mstr where rcs_rlse_id = wk_curr_rlid and
         rcs_shipto = so_ship and
         rcs_shipfrom = sod_site and
         rcs_active
         use-index rcs_index3
      no-lock:
      end.
      assign
         curr_schd_discr_qty = 0
         curr_active_date = rcs_active_date.
      for each rcsd_det where
            rcsd_shipto = rcs_shipto and
            rcsd_shipfrom = rcs_shipfrom and
            rcsd_order = so_nbr and
            rcsd_line = sod_line and
            rcsd_rlse_id = rcs_rlse_id
         no-lock
            break
            by rcsd_order
            by rcsd_line
            by rcsd_rlse_id
            by rcsd_date:

         assign
            curr_schd_discr_qty = curr_schd_discr_qty + rcsd_discr_qty.
         if last-of (rcsd_date)
         then do:
            create ship_schd_day.
            assign
               ssd_nbr       = rcsd_order
               ssd_line      = rcsd_line
               ssd_date      = rcsd_date
               ssd_part      = sod_part
               ssd_desc      = pt_desc1
               ssd_curr_rlid = wk_curr_rlid
               ssd_prev_rlid = wk_prev_rlid
               ssd_curr_flag = yes
               ssd_prev_flag = no
               ssd_curr_qty  = curr_schd_discr_qty
               ssd_prev_qty  = 0
               ssd_curr_cum  = rcsd_cum_qty
               ssd_cum_qty   = rcsd_cum_qty
               ssd_shipfrom  = rcsd_shipfrom
               ssd_shipto    = rcsd_shipto.
            assign curr_schd_discr_qty = 0.
         end. /* do */

      end. /* for each rcsd_det */
      for last rcs_mstr where rcs_rlse_id = wk_prev_rlid and
         rcs_shipto = so_ship and
         rcs_shipfrom = sod_site and
         not rcs_active and
         rcs_active_date <= curr_active_date
         use-index rcs_index3
      no-lock:
      end.
      if available rcs_mstr
      then do:
         assign prev_schd_discr_qty = 0.
         for each rcsd_det where
               rcsd_shipto = rcs_shipto and
               rcsd_shipfrom = rcs_shipfrom and
               rcsd_order = so_nbr and
               rcsd_line = sod_line and
               rcsd_rlse_id = rcs_rlse_id
            no-lock
               break
               by rcsd_order
               by rcsd_line
               by rcsd_rlse_id
               by rcsd_date:
            assign prev_schd_discr_qty =
               prev_schd_discr_qty + rcsd_discr_qty.
            if last-of (rcsd_date)
            then do:
               for first ship_schd_day
                  where ssd_nbr       = rcsd_order
                  and   ssd_line      = rcsd_line
                  and   ssd_date      = rcsd_date
               exclusive-lock:
               end. /* for first */
               if available ship_schd_day
               then
                  assign
                     ssd_prev_flag       = yes
                     ssd_prev_qty        = prev_schd_discr_qty
                     ssd_prev_cum        = rcsd_cum_qty.

               else
               if prev_schd_discr_qty <> 0
               then do:
                  create ship_schd_day.
                  assign
                     ssd_nbr       = rcsd_order
                     ssd_line      = rcsd_line
                     ssd_date      = rcsd_date
                     ssd_part      = sod_part
                     ssd_desc      = pt_desc1
                     ssd_curr_rlid = wk_curr_rlid
                     ssd_curr_qty  = 0
                     ssd_prev_rlid = wk_prev_rlid
                     ssd_curr_cum  = 0
                     ssd_curr_flag = no
                     ssd_prev_flag = yes
                     ssd_prev_cum  = rcsd_cum_qty
                     ssd_prev_qty  = prev_schd_discr_qty
                     ssd_cum_qty   = rcsd_cum_qty
                     ssd_shipfrom  = rcsd_shipfrom
                     ssd_shipto    = rcsd_shipto.

               end. /* else if ...do */
               assign prev_schd_discr_qty = 0.
            end. /* do if last of */
         end. /* for each rcsd_det */
      end. /* if available */
      for each ship_schd_day
         exclusive-lock:
         wk_del_flag = no.
         if ssd_curr_qty = ssd_prev_qty then
            wk_del_flag = yes.
         if not ssd_prev_flag
            or not ssd_curr_flag  then
            wk_del_flag = yes.
         if wk_del_flag = no
         then do:
            assign
               wk_delta = ssd_curr_qty * wk_variance
               wk_upper_lmt = ssd_curr_qty + wk_delta
               wk_lower_lmt = ssd_curr_qty - wk_delta.

            if  ssd_prev_qty < wk_upper_lmt
               and ssd_prev_qty > wk_lower_lmt
            then wk_del_flag = yes.
         end. /* do */
         if wk_del_flag then
            delete ship_schd_day.
         else do:
            assign
               diff_qty = ssd_curr_qty - ssd_prev_qty
               cum_diff_qty = ssd_curr_cum - ssd_prev_cum.

            if diff_qty > 0 then
               wk_percent_qty = diff_qty / ssd_curr_qty.
            else
               assign
                  diff_qty = diff_qty * -1
                  wk_percent_qty = diff_qty / ssd_curr_qty.

            if ssd_curr_qty = 0 then
               wk_percent_qty = 1.
            if cum_diff_qty > 0 then
               wk_percent_cum = cum_diff_qty / ssd_curr_cum.
            else
               assign
                  cum_diff_qty = cum_diff_qty * -1
                  wk_percent_cum = cum_diff_qty / ssd_curr_cum.

            if ssd_curr_cum = 0 then
               wk_percent_cum = 1.
            assign
               ssd_pct_qty = wk_percent_qty * 100
               ssd_pct_cum = wk_percent_cum * 100.
         end. /* do */
      end. /* for each */

      FORM /*GUI*/ 
      with STREAM-IO /*GUI*/  frame ssdhead down width 132 no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame ssdhead:handle).

      FORM /*GUI*/ 
      with STREAM-IO /*GUI*/  frame ssddet down width 132 no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame ssddet:handle).

      clear frame ssdhead all no-pause.
      clear frame ssddet all no-pause.

      for each ship_schd_day
         exclusive-lock
            break
            by ssd_shipfrom
            by ssd_shipto
            by ssd_nbr
            by ssd_line
            by ssd_date:
         if first-of (ssd_line) then do:
            display
               ssd_shipfrom  column-label "Ship-From!Ship-To"
               ssd_nbr       column-label "Order!Line"
               ssd_part
               ssd_desc
               ssd_curr_rlid column-label "Current Release ID!Previous Release ID"
            with frame ssdhead STREAM-IO /*GUI*/ .

            down 1 with frame ssdhead.

            display
               ssd_shipto    @ ssd_shipfrom
               ssd_line      @ ssd_nbr
               ssd_prev_rlid @ ssd_curr_rlid
            with frame ssdhead STREAM-IO /*GUI*/ .

            down 2 with frame ssdhead.
         end.
         assign
            diff_qty = ssd_curr_qty - ssd_prev_qty
            cum_diff_qty = ssd_curr_cum - ssd_prev_cum.
         display
            space(10)
            ssd_date
            ssd_curr_qty column-label "Curr Discrete Qty!Prev Discrete Qty"
            diff_qty     when (diff_qty <> 0)
            ssd_pct_qty  when (ssd_pct_qty <> 0)
            space(8)
            ssd_curr_cum column-label "Current Cum Qty!Previous Cum Qty"
            ssd_pct_cum  when (ssd_pct_cum <> 0)
         with frame ssddet STREAM-IO /*GUI*/ .

         down 1 with frame ssddet.

         display
            ssd_prev_qty @ ssd_curr_qty
            ssd_prev_cum @ ssd_curr_cum
         with frame ssddet STREAM-IO /*GUI*/ .

         down 2 with frame ssddet.

         delete ship_schd_day.
      end. /* for each */
   end. /* for each so_mstr */

   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


end.  /* repeat */

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" shipfrom_from shipfrom_to shipto_from shipto_to part_from part_to so_from so_to var_variance var_abc_class in_rlid_one in_rlid_two "} /*Drive the Report*/
